/*
 * HttpResponse.h
 *
 *  Created on: Jul 11, 2024
 *      Author: root
 */

#ifndef BSP_HTTP_HTTPRESPONSE_H_
#define BSP_HTTP_HTTPRESPONSE_H_
#include "basic_header.h"

namespace bsp {

class HttpResponse {
public:
	HttpResponse();
	virtual ~HttpResponse();

	void setFile(std::string cur_dir, std::string path) {
		dir = cur_dir;
		file = path;
	}

	void setKeepAlive(bool alive) {
		keep_alive = alive;
	}

	int open();
	void close();

	char* getFile() {
		return getMapAddr();
	}
	uint32_t getFileLen() {
		return file_size;
	}
	std::string getHeader();
	char* getMapAddr() {
		return map_addr;
	}

	static void test1();

private:
	const static std::unordered_map<std::string, std::string> SUFFIX_TYPE;
	const static std::unordered_map<int, std::string> CODE_STATUS;

	std::string dir;
	std::string file;
	std::string suffix;
	bool keep_alive;
	int code_num;
	int file_fd;
	int file_size;

	char *map_addr;
};

} /* namespace bsp */

#endif /* BSP_HTTP_HTTPRESPONSE_H_ */
